package iammry.com.factory;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import iammry.com.ui.CustomProgressDialog;

public class ProgressDialogFactory {
	public CustomProgressDialog progressDialog;
	public ProgressDialog mProgressDialog;

	private static ProgressDialogFactory instance = null;

	public void showProgressDialog(Context context) {

		mProgressDialog = ProgressDialog.show(context, null, "正在加载中",
				true, false);
	}

	public void closeProgressDialog() {
		if (mProgressDialog != null || mProgressDialog.isShowing()) {
			mProgressDialog.dismiss();

		}

	}

	public void showDefaultProgress(Context context) {
		progressDialog = CustomProgressDialog.createDialog(context);
		progressDialog.setCancelable(true);

		if (progressDialog != null && !progressDialog.isShowing()) {
			progressDialog.show();
		}
	}

	public void showDefaultProgress(Activity activity, String msg) {
		if (progressDialog == null) {
			progressDialog = CustomProgressDialog.createDialog(activity);
			progressDialog.setCancelable(false);
		}

		if (progressDialog != null && !progressDialog.isShowing()) {
			progressDialog.setMessage(msg);

			progressDialog.show();
		}
	}

	public void dismissProgress(Activity activity) {
		if (progressDialog != null && progressDialog.isShowing()) {
			if (activity != null && !activity.isFinishing()) {
				progressDialog.dismiss();
			}
		}
	}

	public void dismissProgress() {
		if (progressDialog != null && progressDialog.isShowing()) {

			progressDialog.dismiss();
		}
	}

	public CustomProgressDialog getProgressDialog() {

		return progressDialog;
	}

	public static ProgressDialogFactory getInstance() {

		if (instance == null)
		{
			synchronized (ProgressDialogFactory.class) {
				
				if(instance==null)
					
				instance = new ProgressDialogFactory();
			}
			
		}
		return instance;

	}

}
